
/*
'===============================================================================
'  MP.LayerHelper.MP_OBS.BL.HrHurmanOrganizeManager
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using MP.LayerHelper.MP_OBS.BLL;
using MP.LayerHelper.MP_OBS.DAL;
using MP.LayerHelper.MP_OBS.DAL.EntityClasses;
using MP.LayerHelper.MP_OBS.DAL.FactoryClasses;
using MP.LayerHelper.MP_OBS.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;

using MP.Core.Library;
using System.Collections;
namespace MP.LayerHelper.MP_OBS.BLL
{
    public class HrHumanOrganizeManager : HrHumanOrganizeManagerBase
    {
        /// <summary>
        /// Purpose: Class constructor.
        /// </summary>
        public HrHumanOrganizeManager()
        {
            // Nothing for now.
        }

        /// <summary>
        /// Method to create an instance of HrHurmanOrganizeManager
        /// </summary>
        /// <returns>An instant of HrHurmanOrganizeManager class</returns>
        public static HrHumanOrganizeManager CreateInstant()
        {
            return new HrHumanOrganizeManager();
        }
        public HrHumanOrganizeEntity GetByBranch_Depart_Job(Guid Branch, Guid Depart, Guid Job)
        {
            EntityCollection<HrHumanOrganizeEntity> items = new EntityCollection<HrHumanOrganizeEntity>();

            IPredicateExpression predicate = new PredicateExpression();
            predicate.Add(HrHumanOrganizeFields.BranchId == Branch);
            predicate.Add(HrHumanOrganizeFields.DepartId == Depart);
            predicate.Add(HrHumanOrganizeFields.JobId == Job);
            predicate.Add(HrHumanOrganizeFields.IsDeleted == false);

            RelationPredicateBucket filter = new RelationPredicateBucket();
            filter.PredicateExpression.Add(predicate);

            using (DataAccessAdapterBase adapter = new DataAccessAdapterFactory().CreateAdapter())
            {
                adapter.FetchEntityCollection(items, filter);
            }

            if (items != null && items.Count > 0)
                return items[0];
            return null;
        }

        public DataTable GetOrganize()
        {
            string strSQL = "HR_GetOrganize";
            return SqlHelper.ExecuteDataTable(SqlHelper.ConnectionStringOBS, CommandType.StoredProcedure, strSQL);
        }

        public bool CheckExists(Guid Id, Guid BranchId, Guid DepartId, Guid JobId)
        {
            string strSQL = "Select * From HrHumanOrganize ";
            Hashtable param = new Hashtable();
            param["BranchId"] = BranchId;
            param["DepartId"] = DepartId;
            param["JobId"] = JobId;

            if (Id == Guid.Empty)
            {
                strSQL += "Where BranchId=@BranchId and DepartId=@DepartId and JobId=@JobId";
            }
            else
            {
                strSQL += "Where BranchId=@BranchId and DepartId=@DepartId and JobId=@JobId and Id!=@Id";
                param["Id"] = Id;
            }

            DataTable tbl = SqlHelper.ExecuteDataTable(SqlHelper.ConnectionStringOBS, param, CommandType.Text, strSQL);
            if (tbl != null && tbl.Rows.Count > 0)
                return true;
            return false;
        }

        
    }
}
